const {
    getKillDetail,
    getOrder
} = require("../../api/index")


const request = require('../../utils/request')
// pages/grouppick/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // tab切换
        selected: true,
        selected1: false,
        selected2: false,

        detail: {},
        Address: []
    },

    selected: function (e) {
        this.setData({
            selected: true,
            selected1: false,
            selected2: false
        })
    },
    selected1: function (e) {
        this.setData({
            selected: false,
            selected1: true,
            selected2: false
        })
    },
    selected2: function (e) {
        this.setData({
            selected: false,
            selected1: false,
            selected2: true
        })
    },

    // 点击 购买
    handleCcount: function (e) {
        let shop = this.data.detail
        let killlist = JSON.stringify(shop)
        let price = shop.price
        wx.navigateTo({
            url: '/pages/account/index?killlist=' + encodeURIComponent(killlist) + '&price=' + price,
        })

        // let listPrice = this.data.detail
        // getOrder({
        //     listPrice
        // }).then(res => {
        //     wx.showToast({
        //         title: '付款成功',
        //         icon: 'success',
        //     })
        // })
        // let priceAll = this.data.priceList
        // console.log(priceAll);
        // wx.navigateTo({
        //     url: "/pages/payment/index?priceAll=" + priceAll
        // })

    },
    handleAddress(e) {
        console.log(e, '89');
        wx.navigateTo({
            url: '/pages/address/index',
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // 到这边再将字符串转换成对象
        let detaillist = JSON.parse(decodeURIComponent(options.detail))
        this.setData({
            detail: detaillist
        })



    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        request({
            url: '/api/address',
            method: 'get',
            data: {
                isDefault: 1
            }
        }).then(res => {
            console.log(res.data.data.data[0], 'defaultres')
            this.setData({
                Address: res.data.data.data[0].detailAddress
            })
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})